package bairui.international.console.web.controller.user.order;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.lianjing.sh.spring.web.controller.enhance.output.FomatOutput;

import bairui.international.model.domain.jpa.TB_ProductOrderItem;
import bairui.international.service.Service_ProductOrderItem;

/**
 *
 * 详情
 *
 * @generated
 * 
 * @see STest_C_User_Order_Detail_ScoreOrderProductPage 测试
 *
 */
@Controller
public class C_User_Order_Detail_ScoreOrderProductPage
 extends SC_User_Order_Detail_ScoreOrderProductPage 
{
	
	@Autowired private Service_ProductOrderItem service_ProductOrderItem;
	
	/**
	 * 积分产品列表
	 */
	@Action(ScoreOrderProductPage.class)
	@GetMapping(value=ScoreOrderProductPage.RequestMappingValue, consumes=MediaType.APPLICATION_JSON_VALUE)
	public @FomatOutput @ResponseBody Object scoreOrderProductPage(
		HttpServletRequest request, 
		@PathVariable(name=ScoreOrderProductPage.PathVariableName.UserId) long userId, 
		@PathVariable(name=ScoreOrderProductPage.PathVariableName.Id) long id
	) throws Exception {
		org.springframework.data.domain.Page<TB_ProductOrderItem> page = service_ProductOrderItem.page(
				it->ScoreOrderProductPage.Filter.query()
					.and(it.productOrder.id.eq(id)), 
				ScoreOrderProductPage.Output.page(request), 
				it->ScoreOrderProductPage.Output.sort(it, request, new ScoreOrderProductPage.Output.OrderExtends() {
					@Override public Sort gainId(Direction direction) {
						return sort(direction, it.id.product.id);
					}
				})
			);
		//
		return ScoreOrderProductPage.Output.output(
				page
			);
	}
	

}
